﻿#region zh-CHS 2006 - 2007 DemoSoft 团队 | en 2006 - 2007 DemoSoft Team

//     NOTES
// ---------------
//
// This file is a part of the G.O.S.E(Game Online Server Engine) for .NET.
//
//                 2006-2007 DemoSoft Team
//
//
// First Version : by H.Q.Cai - mailto:caihuanqing@hotmail.com

/***************************************************************************
 *
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU Lesser General Public License as published
 *   by the Free Software Foundation; either version 2.1 of the License, or
 *   (at your option) any later version.
 *
 ***************************************************************************/

#region zh-CHS 包含名字空间 | en Include namespace
using System;
using System.Text;
using System.Collections.Generic;
#endregion

namespace Demo_G.O.S.E.ServerEngine.Creature.General
{
    /// <summary>
    /// 最后移动的时间
    /// </summary>
    internal class MovementRecord
    {
        #region zh-CHS 构造和初始化和清理 | en Constructors and Initializers and Dispose
        #region zh-CHS 私有成员变量 | en Private Member Variables
        /// <summary>
        /// 
        /// </summary>
        private DateTime m_End;
        #endregion
        /// <summary>
        /// 
        /// </summary>
        /// <param name="end"></param>
        private MovementRecord( DateTime dateTimeEnd )
        {
            m_End = dateTimeEnd;
        }
        #endregion

        #region zh-CHS 方法 | en Method
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        public bool Expired()
        {
            bool l_bReturn = ( DateTime.Now >= m_End );

            if ( l_bReturn )
                s_InstancePool.Enqueue( this );

            return l_bReturn;
        }
        #endregion

        #region zh-CHS 静态方法 | en Static Method
        /// <summary>
        /// 
        /// </summary>
        private static Queue<MovementRecord> s_InstancePool = new Queue<MovementRecord>();
        /// <summary>
        /// 
        /// </summary>
        /// <param name="end"></param>
        /// <returns></returns>
        public static MovementRecord NewInstance( DateTime dateTimeEnd )
        {
            MovementRecord l_MovementRecord;

            if ( s_InstancePool.Count > 0 )
            {
                l_MovementRecord = s_InstancePool.Dequeue();
                l_MovementRecord.m_End = dateTimeEnd;
            }
            else
                l_MovementRecord = new MovementRecord( dateTimeEnd );

            return l_MovementRecord;
        }
        #endregion
    }
}
#endregion

